package com.zjgsu.nftplatform.controller;

import com.zjgsu.nftplatform.pojo.Result;
import com.zjgsu.nftplatform.pojo.ResultCode;
import com.zjgsu.nftplatform.service.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ahy231
 * @date 2022/5/4 20:43
 * @description
 */
@Api(tags = "智能合约设置")
@RestController
@RequestMapping("/config")
public class ConfigController {

    private final ConfigService configService;

    public ConfigController(ConfigService configService) {
        this.configService = configService;
    }

    @ApiOperation("更换nft合约地址")
    @PostMapping("/nftAddress")
    public Result nftAddress(@ApiParam("地址") @RequestParam String address) {
        try {
            return new Result(ResultCode.SUCCESS, configService.nftAddress(address));
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(ResultCode.FAILED, e.getMessage());
        }
    }

    @ApiOperation("更换purchase合约地址")
    @PostMapping("/purchaseAddress")
    public Result purchaseAddress(@ApiParam("地址") @RequestParam String address) {
        try {
            return new Result(ResultCode.SUCCESS, configService.purchaseAddress(address));
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(ResultCode.FAILED, e.getMessage());
        }
    }
}
